package com.zhaoc.service.impl;

import com.zhaoc.dao.PermissionRepository;
import com.zhaoc.domain.system.Permission;
import com.zhaoc.domain.system.User;
import com.zhaoc.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>title:com.zhaoc.service.impl</p>
 * date:2018/8/21 0021
 * time:17:50
 * author:赵成
 * user:13566
 */
@Service
@Transactional
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private PermissionRepository permissionRepository;

    @Override
    public List<Permission> findByUser(User user) {
        //admin有所有的权限
        if (user.getUsername().equals("admin")) {
            return permissionRepository.findAll();
        }else {
            return permissionRepository.findByUser(user.getId());
        }
    }

    //查询所有权限
    @Override
    public List<Permission> findAll() {
        return permissionRepository.findAll();
    }

    //保存权限
    @Override
    public void save(Permission permission) {
        permissionRepository.save(permission);
    }
}
